import 'package:PollOnLine/utils/toast_utils.dart';
import 'package:PollOnLine/values/MyColors.dart';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:signature/signature.dart';

import '../../../main.dart';
import 'signature_logic.dart';

/// 签名
class SignaturePageIpad extends StatefulWidget {
  final String title;

  const SignaturePageIpad({Key? key, required this.title}) : super(key: key);

  @override
  State<SignaturePageIpad> createState() => _SignaturePageIpadState();
}

class _SignaturePageIpadState extends State<SignaturePageIpad> {
  final logic = Get.put(SignatureLogic());
  final state = Get.find<SignatureLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MyColors.FFEDF1F5,
      appBar: BrnAppBar(title: "电子签名", themeData: XxxConfigUtils.defaultAppBarConfig),
      body: Container(
        margin: EdgeInsets.only(left: 32.r, right: 32.r, top: 10.r, bottom: 5.r),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(6.r),
        ),
        child: BrnShadowCard(
          color: Colors.white,
          circular: 6.r,
          spreadRadius: 0.11.r,
          blurRadius: 0.4.r,
          child: Stack(
            children: [
              Center(
                child: Text("在此处签名", style: TextStyle(fontSize: 38.r, color: const Color(0x06000000))),
              ),
              Signature(
                key: const Key('signature'),
                controller: logic.controller,
                height: Get.height - 128,
                backgroundColor: Colors.transparent,
              ),
            ],
          ),
        ),
      ),
      bottomNavigationBar: SafeArea(
        child: Container(
          margin: EdgeInsets.only(left: 32.r, right: 32.r, bottom: 12.r),
          padding: EdgeInsets.only(left: 32.r, right: 32.r),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              Expanded(
                child: OutlinedButton(
                  style: OutlinedButton.styleFrom(
                    padding: EdgeInsets.only(left: 32.r, right: 32.r, top: 0.r, bottom: 0.r),
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
                    side: const BorderSide(color: MyColors.FF1060DD),
                    minimumSize: Size(100.r, 40.r),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      const Icon(Icons.refresh, color: MyColors.FF1060DD, size: 20),
                      Padding(padding: EdgeInsets.all(10.r), child: Text("重签", style: TextStyle(color: MyColors.FF1060DD, fontSize: 12.r)))
                    ],
                  ),
                  onPressed: () {
                    setState(() => logic.controller.clear());
                  },
                ),
              ),
              SizedBox(
                width: 32.r,
              ),
              // STOP Edit
              Expanded(
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    padding: EdgeInsets.only(left: 32.r, right: 32.r, top: 0.r, bottom: 0.r),
                    backgroundColor: MyColors.FF0144B0,
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
                    minimumSize: Size(100.r, 40.r),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      const Icon(Icons.check, color: Colors.white, size: 20),
                      Padding(padding: EdgeInsets.all(10.r), child: Text("确认", style: TextStyle(color: Colors.white, fontSize: 12.r)))
                    ],
                  ),
                  onPressed: () {
                    setState(() => logic.controller.disabled = !logic.controller.disabled);
                    if (logic.controller.disabled) {
                      logic.uploadFile();
                    } else {
                      toast.show("取消");
                    }
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<SignatureLogic>();
    super.dispose();
  }
}
